REMOTE=$1
cat << EOF

For this to work, you need:
ROOT password of REMOTE server
SUDO access on SAPRMT01
Personal account on SAPLXS01 with SUDO access (for Admin Central updates)

##########################################################################################################
-- On saprmt01:
##########################################################################################################

bash

sudo ssh-keygen -R $REMOTE
sudo su - root -c /usr/local/scripts/ssh-copy-id $REMOTE

for file in /etc/syslog.conf /etc/profile /.profile /etc/kshrc /etc/motd \\
/etc/zlogout /etc/sudoers /etc/auto_master /etc/auto_central /etc/auto_home; \\
 do sudo scp \$file $REMOTE:\$file; done
echo "chsec -f /etc/security/login.cfg -s usw -a shells=/bin/sh,/bin/bsh,/bin/csh,\\
/bin/ksh,/bin/tsh,/bin/ksh93,/usr/bin/sh,/usr/bin/bsh,/usr/bin/csh,/usr/bin/ksh,\\
/usr/bin/tsh,/usr/bin/ksh93,/usr/bin/rksh,/usr/bin/rksh93,/usr/sbin/uucp/uucico,\\
/usr/sbin/sliplogin,/usr/sbin/snappd,/usr/bin/bash,/bin/bash,/usr/bin/zsh,\\
/bin/zsh,/bin/git-shell,/bin/false" | sudo ssh -x -T -q $REMOTE "cat | /bin/sh"
sudo ssh -x -T -q $REMOTE "/usr/bin/startsrc -s automountd; sleep 2; automount -v"
sudo ssh -x -T -q $REMOTE "cd /central/depot/softwares/SSH && installp -a -d . \\
-Y openssl.base openssh.base.client openssh.base.server; stopsrc -s sshd && sleep 2 && startsrc -s sshd"
sudo ssh -x -T -q $REMOTE "mkdir -p /var/adm/syslog && touch /var/adm/syslog/syslog.log && /bin/refresh -s syslogd"
sudo ssh -x -T -q $REMOTE "cd /central/depot/rpm; ./install_gnu" 
sudo -u saunix ssh-keygen -R $REMOTE
sudo ssh -x -T -q $REMOTE "/usr/bin/mkgroup id=600 admin; \\
`/usr/local/scripts/get_user_create_cmd saunix`"
sudo -u saunix cat ~saunix/.ssh/id_rsa.pub | sudo ssh -x -T -q $REMOTE "su - saunix -c 'test -d ~saunix/.ssh || \\
mkdir -m 700 ~saunix/.ssh ; cat > ~saunix/.ssh/authorized_keys; \
chmod 600 ~saunix/.ssh/authorized_keys'"
sudo ssh -x -T -q $REMOTE "`/usr/local/scripts/get_user_create_cmd git`; chuser account_locked=true git"
echo "if [ ! -d /usr/local ]; then mkdir -p -m 755 /usr/local; fi" | sudo ssh -x -T -q $REMOTE "cat | bash"
echo "ln -sf /var/code/sap/scripts /usr/local/scripts" | sudo ssh -x -T -q $REMOTE "cat | bash"

/usr/local/scripts/update_code_by_commit.sh -h $REMOTE -r sap -f
/usr/local/scripts/create_user.sh -h $REMOTE -u `lsgroup -a users admin | tr ',' '\n' | grep '^b0' | xargs | tr ' ' ','`
(cd /tmp; sudo /usr/local/scripts/sync_keys.sh -h $REMOTE -u `cat /etc/passwd|grep '^b0'| cut -d: -f1 | xargs | sed 's/ /,/g'`)
(cd /tmp; sudo /usr/local/scripts/update_baconf.sh -h $REMOTE)
(cd /tmp; sudo /usr/local/scripts/remove_root_login $REMOTE)

######################
# Admin central
######################

echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEArxU0LOhIKVZkMCkBBrIQmUIYXcsKR6oXrwoU1JR6Yx98yn2cqOh3tmPFbROtRvt+3TACBWzAC3u52BBNIk+v5bvp3J6me+Z4EsBzTh7UWJOz62B7F7DAQjpwpIHKVkrw12ey3CXkq+nusxnyOfPB73bOt9xETteFHbWa1Cci3i8= saunix@saplxs01' | sudo -u saunix ssh -x -q $REMOTE 'cat >> /home/saunix/.ssh/authorized_keys'
ssh -x -t saplxs01 "sudo su - saunix -c \\"cd /home/saunix/opmgt/bin; ./mPushScripts.pl --host=$REMOTE;./mPullData.pl --host=$REMOTE\\""

##########################################################################################################
-- On the target server
##########################################################################################################

/usr/local/scripts/kerberos_install
/usr/local/scripts/change_root_home

EOF
